import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../shared/styles.dart';
import '../shared/colors.dart';
import '../shared/inputFields.dart';
import 'package:page_transition/page_transition.dart';
import './signup_page.dart';
import './dash_board.dart';

class SignInPage extends StatefulWidget {
  final String? pageTitle;

  SignInPage({Key? key, this.pageTitle}) : super(key: key);

  @override
  _SignInPageState createState() => _SignInPageState();
}

class _SignInPageState extends State<SignInPage> {
  String name = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          elevation: 0,
          backgroundColor: white,
          title: Text('返回注册',
              style: TextStyle(
                  color: Colors.black, fontFamily: 'Poppins', fontSize: 15)),
          actions: <Widget>[
            TextButton(
              onPressed: () {
                // Navigator.of(context).pushReplacementNamed('/signup');
                Navigator.pushReplacement(
                    context,
                    PageTransition(
                        type: PageTransitionType.rightToLeft,
                        child: SignUpPage()));
              },
              child: Text('登陆', style: contrastText),
            )
          ],
        ),
        body: ListView(
          shrinkWrap: true,
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(left: 18, right: 18),
              height: 245,
              width: double.infinity,
              decoration: authPlateDecoration,
              child: Stack(
                children: <Widget>[
                  Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      const Text('欢迎回来!', style: h3),
                      // Text('Howdy, let\'s authenticate', style: taglineText),
                      fryoTextInput('请输入账号', onChanged: (String value) {
                        setState(() {
                          name = value;
                        });
                      }),
                      fryoPasswordInput('请输入密码'),
                      TextButton(
                        onPressed: () {},
                        child: const Text('忘记密码?', style: contrastTextBold),
                      )
                    ],
                  ),
                  Positioned(
                    bottom: 15,
                    right: -15,
                    child: TextButton(
                      onPressed: () {
                        if (name.length < 2 || name.length > 5) {
                          Fluttertoast.showToast(msg: '账号长度必须在2-5之间');
                        } else {
                          Navigator.pushReplacement(
                              context,
                              PageTransition(
                                  type: PageTransitionType.rightToLeft,
                                  child: Dashboard(
                                    pageTitle: '',
                                  )));
                        }
                      },
                      style: TextButton.styleFrom(
                        foregroundColor: primaryColor,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(4),
                        ),
                      ),
                      child:
                          const Icon(Icons.arrow_forward, color: Colors.black),
                    ),
                  )
                ],
              ),
            ),
          ],
        ));
  }
}
